<?php

include_once 'Expression.php';
include_once 'ExpressionCollection.php';
include_once 'TypeReference.php';

/**
 * Represents an expression that creates a new object.
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/ObjectCreateExpressionExample.php 
 */

class ObjectCreateExpression extends Expression
{
    /**
     * The ObjectCreateExpression constructor
     * @param TypeReference $CreateType The class of the object to create
     * @param ExpressionCollection $Parameters The parameters for the class constructor
     */
    
    public function __construct(
        TypeReference $CreateType, ExpressionCollection $Parameters = null)
    {
        parent::__construct();
        
        $this->set_CreateType($CreateType);
        $Parameters == null ? 
            $this->Parameters = new ExpressionCollection() : 
            $this->set_Parameters($Parameters);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'CreateType')
        {
            $this->set_CreateType($value);
        }
        
        if($name == 'Parameters')
        {
            $this->set_Parameters($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'CreateType')
        {
            return $this->get_CreateType();
        }
        
        if($name == 'Parameters')
        {
            return $this->get_Parameters();
        }
    }
    
    /**
     * The $CreateType getter method
     * @return TypeReference 
     */
    
    public function get_CreateType()
    {
        return $this->CreateType;
    }
    
    /**
     * The $CreateType setter method
     * @param TypeReference $CreateType 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert (true) throws PHPUnit_Framework_Error
     */

    public function set_CreateType(TypeReference $CreateType)
    {
        $this->CreateType = $CreateType;
    }

    /**
     * The $Parameters getter method
     * @return ExpressionCollection 
     */
    
    public function get_Parameters()
    {
        return $this->Parameters;
    }

    /**
     * The $Parameters setter method
     * @param ExpressionCollection $Parameters 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert (true) throws PHPUnit_Framework_Error
     */
    
    public function set_Parameters(ExpressionCollection $Parameters)
    {
        $this->Parameters = $Parameters;
    }

    /**
     * The class of the object to create
     * @var TypeReference 
     */
    
    private $CreateType;
    
    /**
     * The parameters for the class constructor
     * @var ExpressionCollection
     */
    
    private $Parameters;
}

?>
